from selenium import webdriver
import time

# 初始化Chrome浏览器
driver = webdriver.Chrome()

# 访问传智教育网站
driver.get("https://www.itheima.com")
driver.maximize_window()

try:
    # 获取所有Cookie信息
    cookies = driver.get_cookies()

    # 打印Cookie信息到控制台
    print("传智教育页面的Cookie信息：")
    for cookie in cookies:
        print(
            f"Name: {cookie['name']}, Value: {cookie['value']}, Domain: {cookie['domain']}, Path: {cookie['path']}, Expiry: {cookie.get('expiry')}")

    # 截图保存
    driver.save_screenshot("itheima_cookies.png")
    print("截图已保存")

except Exception as e:
    print(f"操作失败：{e}")

finally:
    # 关闭浏览器
    driver.quit()